<?php

class InstallModule extends CWebModule {

    public $defaultController = 'setup';
    private $_assetsUrl;

    public function init() {
        // this method is called when the module is being created
        // you may place code here to customize the module or the application
        // import the module-level models and components
        $this->setImport(array(
            'install.models.*',
            'install.components.*',
        ));
        
        $this->layoutPath = Yii::getPathOfAlias($this->id.'.views.layouts');
    }

    public function getVersion() {
        return '1.0';
    }

    public function beforeControllerAction($controller, $action) {
        if (parent::beforeControllerAction($controller, $action)) {
            // this method is called before any module controller action is performed
            // you may place customized code here
            return true;
        }
        else
            return false;
    }

    /**
     * Publishes the module assets path.
     * @return string the base URL that contains all published asset files.
     */
    public function assetsUrl() {
        if ($this->_assetsUrl === null) {
            $assetsPath = Yii::getPathOfAlias($this->name . '.assets');
            // Republish the assets if debug mode is enabled.
            if (YII_DEBUG)
                $this->_assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, true);
            else
                $this->_assetsUrl = Yii::app()->assetManager->publish($assetsPath);
        }
        return $this->_assetsUrl;
    }
}